From 7a197e5b65637d94f3c215a74950a63869fbb719 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 11 Apr 2011 10:42:03 +0200 Subject: [PATCH] [broadway] Fix up frame size calculation Turns out that offsetTop/Left doesn't contain the border, so we need to manually add that in. --- gdk/broadway/broadway.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js index 8cefb061c4..3494c78459 100644 --- a/gdk/broadway/broadway.js +++ b/gdk/broadway/broadway.js @@ -322,15 +322,44 @@ function getTransientToplevel(surface) return null; } +function getStyle(el, styleProp) +{ + if (el.currentStyle) { + return el.currentStyle[styleProp]; + } else if (window.getComputedStyle) { + var win = el.ownerDocument.defaultView; + return win.getComputedStyle(el, null).getPropertyValue(styleProp); + } + return undefined; +} + +function parseOffset(value) +{ + var px = value.indexOf("px"); + if (px > 0) + return parseInt(value.slice(0,px)); + return 0; +} + function getFrameOffset(surface) { - var x = 1; - var y = 1; + var x = 0; + var y = 0; var el = surface.canvas; while (el != null && el != surface.frame) { x += el.offsetLeft; y += el.offsetTop; + + /* For some reason the border is not includes in the offsets.. */ + x += parseOffset(getStyle(el, "border-left-width")); + y += parseOffset(getStyle(el, "border-top-width")); + el = el.offsetParent; } + + /* Also include frame border as per above */ + x += parseOffset(getStyle(el, "border-left-width")); + y += parseOffset(getStyle(el, "border-top-width")); + return {x: x, y: y}; } -- 2.30.2